package com.guyaning.deyson_core.core.wechat;

import android.app.Activity;

import com.guyaning.deyson_core.core.app.Config_Type;
import com.guyaning.deyson_core.core.app.Deyson;
import com.guyaning.deyson_core.core.wechat.callbacks.IWeChatSignInCallBack;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * Created by Administrator on 2018/5/8.
 */

public class LatteWeChat {

    public static final String APP_ID = Deyson.getConfiguration(Config_Type.WE_CHAT_APP_ID);

    public static final String APP_SECRET = Deyson.getConfiguration(Config_Type.WE_CHAT_APP_SECRET);

    private IWeChatSignInCallBack signInCallBack = null;

    private final IWXAPI WXAPI;

    private static final class Holder {
        private static final LatteWeChat INSTANCE = new LatteWeChat();
    }

    public static LatteWeChat getInstance() {
        return Holder.INSTANCE;
    }

    public LatteWeChat onSignInSuccess(IWeChatSignInCallBack callBack){
        this.signInCallBack = callBack;
        return this;
    }


    public IWeChatSignInCallBack getSignInCallBack(){
        return signInCallBack;
    }

    private LatteWeChat() {
        final Activity activity = Deyson.getConfiguration(Config_Type.ACTIVITY);

        WXAPI = WXAPIFactory.createWXAPI(activity, APP_ID, true);

        WXAPI.registerApp(APP_ID);
    }

    public final IWXAPI getWXAPI() {
        return WXAPI;
    }

    public final void signIn() {
        final SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "random_state";
        WXAPI.sendReq(req);
    }
}
